<?php
require_once 'PHPUnit/Framework.php';

require_once 'Cameo/SMS.php';
require_once 'Cameo/SMS/Message.php';

class Cameo_SMS_MessageTests extends PHPUnit_Framework_TestCase {
	
	/**
	 * @var Cameo_SMS_Gateway_Test
	 */
	protected $_gateway;
	
	protected $_sample_message_data = array(
		'to' => '12345',
		'text' => 'body text',
		'from' => 'Cameo SMS tester',
		'unicode' => true
	);
	
	public function setUp() {
		$this->_gateway = Cameo_SMS::factory('Test');
	}
	
	public function testSendNoGateway() {
		$this->setExpectedException('Cameo_SMS_Exception', 'Cannot send the message, no gateway provided.');
		
		$message = new Cameo_SMS_Message();
		$message->send();
	}
	
	public function testBatchNoGateway() {
		$this->setExpectedException('Cameo_SMS_Exception', 'Cannot send the message, no gateway provided.');
		
		$message = new Cameo_SMS_Message();
		$message->batch(array('123456789'));
	}
	
	public function testSend() {
		$message = $this->_gateway->createMessage();
		$message->setText('body text');
		$message->setTo('12345');
		
		$resp = $message->send();
		
		$this->assertType('array', $resp);
	}
	
	public function testBatch() {
		$message = $this->_gateway->createMessage();
		$message->setText($this->_sample_message_data['text']);
		
		$resp = $message->batch(array('1', '2', '3'));
		
		$this->assertType('array', $resp);
		$this->assertEquals(3, count($resp));
	}
	
	public function testSendWithASpecifiedGateway() {
		$message = new Cameo_SMS_Message();
		$message->setText($this->_sample_message_data['text']);
		$message->setTo($this->_sample_message_data['to']);
		
		$resp = $message->send(array(), $this->_gateway);
		
		$this->assertType('array', $resp);
		$this->assertEquals(1, count($this->_gateway->sent_messages));
	}
	
	public function testSetMessageUnicode() {
		$message = $this->_gateway->createMessage();
		$message->setText($this->_sample_message_data['text'], $this->_sample_message_data['unicode']);
		$message->setTo($this->_sample_message_data['to']);
		
		$resp = $message->send();
		
		$this->assertTrue($this->_gateway->sent_messages[0]['unicode']);
	}
	
}